﻿using System;
using System.Data;

namespace wuliuback
{
    public partial class InfoCount : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string user_id = Request["user_id"];

            string code = "";
            string msg = "''";
            string goodsCount = "";
            string truckCount = "";
            string favoriteInfoCount = "";
            string favoriteUserCount = "";

            string sql = " SELECT a.Expr1, b.Expr1 AS Expr2, d.Expr1 AS Expr3,e.Expr1 as expr4"
                        +" FROM (SELECT COUNT(*) AS Expr1"
                                +" FROM t_goods AS g"
                                +" WHERE (User_id = '"+user_id+"' and g.status>-1)) AS a CROSS JOIN"
                        +" (SELECT COUNT(*) AS Expr1"
                                +" FROM t_truck AS t"
                                + " WHERE (user_id = '" + user_id + "' and t.status>-1)) AS b CROSS JOIN"
                        +" (SELECT COUNT(*) AS Expr1"
                                +" FROM t_favorite AS f"
                                + " WHERE (user_id = '" + user_id + "') AND (status >= 0) and (type= 1 or type=2) ) AS d cross join"
                        +" (SELECT COUNT(*) AS Expr1"
                                + " FROM t_favorite AS f"
                                + " WHERE (user_id = '" + user_id + "') AND (status >= 0) and (type= 3) ) AS e";
            
            DbHelper dbHelper=new DbHelper();
            DataSet dataSet = dbHelper.Select(sql);
            DataTable table=dataSet.Tables[0];
            if (table.Rows.Count <= 0)
            {
                msg = "失败";
                code = "-1";
            }
            else
            {
                code = "0";
                msg = "成功";
                goodsCount = table.Rows[0][0].ToString();
                truckCount = table.Rows[0][1].ToString();
                favoriteInfoCount = table.Rows[0][2].ToString();
                favoriteUserCount = table.Rows[0][3].ToString();
            }

            Response.Output.WriteLine("{\"code\":\"" + code + "\",\"msg\":\"" + msg
                + "\",\"goodsCount\":\"" + goodsCount + "\",\"truckCount\":\"" +truckCount
                + "\",\"favoriteInfoCount\":\"" + favoriteInfoCount + "\",\"favoriteUserCount\":\"" + favoriteUserCount + "\"}");
        }
    }
}
